﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ChungNhanSinhVien.Entities;
using ChungNhanSinhVien.Entities.SinhVien;


namespace ChungNhanSinhVien.Infrastructures
{
    public class SessionManager
    {
        public SessionManager() { }

        public static void ClearSession() 
        {
            HttpContext.Current.Session.Clear();    
        }

        public static void Logout()
        {
            SessionManager.nsr = null;
            SessionManager.user = null;
        }

        public static bool IsLogin()
        {
            return (SessionManager.nsr != null || SessionManager.user != null);
        }

        public static bool IsAdminLogin()
        {
            return (SessionManager.nsr != null);
        }

        public static bool IsUserLogin()
        {
            return (SessionManager.user!=null);
        }

        #region "Thuoc tinh admin, user"
        public static AdminAccount nsr
        {
            get {
                if (HttpContext.Current.Session["nsr"] == null)
                    return null;
                return (AdminAccount)(HttpContext.Current.Session["nsr"]);
            }
            set {
                HttpContext.Current.Session["nsr"] = value;
            }
        }

        public static SinhVien user
        {
            get {
                if (HttpContext.Current.Session["User"] == null)
                    return null;
                return (SinhVien)(HttpContext.Current.Session["User"]);
            }
            set {
                HttpContext.Current.Session["User"] = value;
            }
        }

        public static int loaicnID
        {
            get
            {
                if (HttpContext.Current.Session["loaicnid"] == null)
                    return 0;
                return (int)(HttpContext.Current.Session["loaicnid"]);
            }
            set
            {
                HttpContext.Current.Session["loaicnid"] = value;
            }
        }

        public static string studentID
        {
            get
            {
                if (HttpContext.Current.Session["studentID"] == null)
                    return "";
                return (HttpContext.Current.Session["studentID"].ToString());
            }
            set
            {
                HttpContext.Current.Session["loaicnid"] = value;
            }
        }

        public static string image
        {
            get
            {
                if (HttpContext.Current.Session["image"] == null)
                    return null;
                return (HttpContext.Current.Session["image"]).ToString();
            }
            set
            {
                HttpContext.Current.Session["image"] = value;
            }
        }
       
        #endregion
        public static void ClearImage()
        {
            SessionManager.image = null;
        }
    }
}